<template>
  <div class="home">
    <el-input v-model="input" @input="searchs" placeholder="请输入内容"></el-input>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="title" label="名称" width="180"> </el-table-column>
      <el-table-column prop="detail" label="描述" width="880"> </el-table-column>
      <el-table-column prop="price" label="价格"> </el-table-column>
      <el-table-column prop="id" label="id"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.row.id)"
            type="text"
            size="small"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
      <el-pagination
    layout="prev, pager, next"
    @current-change="handleCurrentChange"
    :total="total">
  </el-pagination>
  </div>
</template>

<script>
import axios from "axios"
export default {
  data(){
    return{
      tableData: [],
      input: '',
      total:0
    }
  },
  methods:{
    async http(pageIndex=0,pageSize=5){
      const res=await axios.get('/api/lists',{
        params:{
          pageIndex,
          pageSize,
          value:this.input
        }
      })
      this.tableData=res.data.data
      console.log(res.data);
      this.total=res.data.total
    },
    async del(id){
      const res=await axios.delete('/api/delList',{
        params:{
          id
        }
      })
      console.log(res)
      if(res.data.code===200){
        this.$message({
          message: res.data.mes,
          type: 'success'
        });
      }else{
        this.$message.error(res.data.mes);
      }
    },
    searchs(){
      this.http()
    },
    handleCurrentChange(index){
      this.http(index)
    },
    deleteRow(scope){
      this.del(scope)
      this.http()
    }
  },
  created(){
    this.http()
  },
  
};
</script>
